package org.itboys.core.controller.web.dispatch;

import org.itboys.admin.tools.AdminSessionHolder;
import org.itboys.core.common.SundayCommonConstants;
import org.itboys.core.entity.mongo.SundayMember;
import org.itboys.core.entity.mongo.dispatch.SundayDispatchOrder;
import org.itboys.core.service.mongo.web.SundayDispatchService;
import org.itboys.core.service.mongo.web.SundayMemberService;
import org.itboys.core.util.ResponseMessage;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author：贾琦磊
 * @Date：2019/1/7
 * @Description：平台调度单
 */
@Controller
@RequestMapping("/sunday/web/dispatch")
public class SundayDispatchController extends BaseController {
    @Autowired
    private SundayMemberService memberService;
    @Autowired
    private SundayDispatchService dispatchService;
    @RequestMapping("/index")
    public String index(HttpServletResponse response, HttpServletRequest request) {
        return "/sunday/dispatch/index";
    }
    @RequestMapping("/select")
    public void select(HttpServletRequest request, HttpServletResponse response) {
        Long userId = AdminSessionHolder.getAdminUserId();
        SundayMember member = memberService.getMemberByUserId(userId);
        PageResult<SundayDispatchOrder> result = dispatchService.select(request, member, SundayCommonConstants.dispatch_select_type_review);
        JsonPageUtils.renderJsonPage(result.getTotal(), result.getData(), response);
    }
    @RequestMapping("/update")
    public void update(HttpServletRequest request,HttpServletResponse response
    ,@RequestParam("id")Long id
    ,@RequestParam("state")Integer state){
        dispatchService.update(id,"state",state);
        ResponseMessage.success();
    }

}
